<% response.setHeader("Cache-Control", "no-store"); %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>Nahrát fotku</title>
    <script type="text/javascript">

        function submitBulkAction(blkAction) {
            if (confirm('Jste si opravdu jisti?')) {
                bulkAction.value=blkAction;
                bulkActionsForm.submit();
            }
        }

    </script>
</head>
<body>

<jsp:useBean id="albumBean" scope="session"
             type="cz.vse.javaee.album.AlbumPageBean"/>

<h1>Nahrát fotku</h1>

<form action="album" method="post" enctype="multipart/form-data">
    <input type="hidden" name="action" value="upload"/><br>
    <label for="name">Název:</label><br>
    <input id="name" type="text" name="name"/><br>
    <label for="description">Popis:</label><br>
    <textarea id="description" name="description" rows="5" cols="30"></textarea><br>
    <label for="file">Soubor:</label><br>
    <input id="file" type="file" name="file"/><br>
    <label for="album">Album:</label><br>
    <input id="album" type="text" name="album" value="${albumBean.paginator.albumName}"/><br>
    <input type="submit" value="Nahrát"/><br>
</form>

<h2>Fotky</h2>

<form action="album" method="post">
    <input id="act" type="hidden" name="action" value=""/>
    <input type="submit" value="První" onclick="act.value='first'"/>
    <input type="submit" value="Předchozí" onclick="act.value='previous'"/>
    <input type="submit" value="Další" onclick="act.value='next'"/>
    <input type="submit" value="Poslední" onclick="act.value='last'"/>
</form>

<br>

<form id="selectAlbumForm" action="album" method="post">
    <input type="hidden" name="action" value="selectAlbum"/>
    <label for="selectedAlbum">Select album:</label><br>
    <select id="selectedAlbum" name="selectedAlbum" size="1" onchange="selectAlbumForm.submit()">
        <c:forEach items="${albumBean.albumDAO.albums}" var="album">
            <c:choose>
                <c:when test="${album.name==albumBean.paginator.albumName}">
                    <option value="${album.name}" selected="selected">${album.name}</option>
                </c:when>
                <c:otherwise>
                    <option value="${album.name}">${album.name}</option>
                </c:otherwise>
            </c:choose>
        </c:forEach>
    </select><br>
</form>


Počet fotek:${albumBean.paginator.size} <br>
Stránka:${albumBean.paginator.index + 1} <br>

<table>
    <tr>
        <td>Pořadí</td>
        <td>Název</td>
        <td>Popis</td>
        <td>Detail</td>
        <td>Výběr</td>
    </tr>

  <form id="bulkActionsForm" action="album" method="post">
    <input id="bulkAction" type="hidden" name="action" value=""/>
    <c:forEach items="${albumBean.photos}" var="photo"
               varStatus="loopStatus">
        <tr>
            <td>${loopStatus.index +
            albumBean.paginator.index*albumBean.paginator.pageSize}</td>
            <td>${photo.photoName}</td>
            <td>${photo.photoDescription}</td>
            <td><a href="album?action=detail&photo=${photo.photoName}">
                <img src="photo/${photo.photoName}?iconized=true" alt="${photo.photoName}"
                     ></a></td>
            <td><input type="checkbox" name="selectedPhoto" value="${photo.photoId}"/></td>
        </tr>
    </c:forEach>
    <input type="button" value="Odstranit" onclick="submitBulkAction('removeSelected')"/>
  </form>
</table>

<form action="album" method="post">
    <input type="hidden" name="action" value="setPageSize"/>
    <label for="pageSize">Velikost stránky:</label><br>
    <input id="pageSize" type="text" name="pageSize"
           value="${albumBean.paginator.pageSize}"/>
    <input type="submit" value="Nastavit"/>
</form>

<br>
<a href="export.jsp">Export</a>

</body>

</html>
